/**
 * Copyright(C) 2012 Luvina Software Company
 *
 * MstGroupLogicImpl.java, 2/1/2013, bacdv
 */
package net.luvina.manageuser.logic.impl;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import net.luvina.manageuser.dao.MstGroupDao;
import net.luvina.manageuser.hibernate.MstGroup;
import net.luvina.manageuser.logic.MstGroupLogic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * get list group
 *
 * @author bacdv
 *
 */
@Service("GroupLogic")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = false, rollbackFor = { Throwable.class })
public class MstGroupLogicImpl implements MstGroupLogic {
    @Autowired
    private MstGroupDao mstGroupDao;

    /*
     * (non-Javadoc)
     *
     * @see
     * net.luvina.manageuser.logic.MstGroupLogic#getListItemGroup(java.lang.
     * String)
     */
    public List<SelectItem> getListItemGroup(String stringValue) {
        List<SelectItem> result = new ArrayList<SelectItem>();
        SelectItem item1 = new SelectItem();
        item1.setValue("0");
        item1.setLabel(stringValue);
        result.add(item1);

        List<MstGroup> mstGroup = mstGroupDao.getListGroup();
        if (mstGroup != null && mstGroup.size() > 0) {
            for (int i = 0; i < mstGroup.size(); i++) {
                MstGroup mGroup = mstGroup.get(i);
                SelectItem selectItem = new SelectItem();
                selectItem.setValue(String.valueOf(mGroup.getGroupId()));
                selectItem.setLabel(mGroup.getGroupName());
                result.add(selectItem);
            }
        }
        return result;
    }
}
